package com.liu.sx.controller;

import com.liu.sx.common.entity.Result;
import com.liu.sx.common.status.CodeEnum;
import com.liu.sx.entity.User;
import com.liu.sx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/add")
    public Result addUser(@RequestBody User user){

        userService.addUser(user);

        return new Result(true, CodeEnum.OK.getCode(),"恭喜您！用户注册成功！");

    }

    @GetMapping("/{id}")
    public Result getUser(@PathVariable  String id){


        return  new Result(true,CodeEnum.OK.getCode(),"查询用户成功");
    }
    @PostMapping("/{id}/{name}")
    public Result edit(@PathVariable  String id,@PathVariable String name){
        System.out.println("id:"+id+"name:"+name);

        return  new Result(true,CodeEnum.OK.getCode(),"编辑用户陈宫");
    }


    @PostMapping("/{id}")
    public Result edit(@PathVariable  String id,User user){
        System.out.println("id:"+id+"name:"+user.toString());

        return  new Result(true,CodeEnum.OK.getCode(),"传递对象成功");
    }


    @PostMapping("/json")
    public Result json(@RequestBody User user){
        System.out.println("josn========:"+user.toString());

        return  new Result(true,CodeEnum.OK.getCode(),"注册成功");
    }
}
